//
//  EmoticonTextAttachment.swift
//  Super_WeiBo
//
//  Created by SuperMac on 16/5/31.
//  Copyright © 2016年 lc. All rights reserved.
//

import UIKit

class EmoticonTextAttachment: NSTextAttachment {
    
    /// 保存对应表情的文字
    var chs: String?
    
    // 根据表情模型，创建表情字符串
    class func imageText(emoticon: Emoticon, font: UIFont) -> NSAttributedString
    {
        // 创建附件
        let attachment = EmoticonTextAttachment()
        attachment.chs = emoticon.chs
        attachment.image = UIImage(contentsOfFile: emoticon.imagePath!)
        // 设置附件大小
        let s = font.lineHeight
        attachment.bounds = CGRect(x: 0, y: -4, width: s, height: s)
        // 创建属性字符串
        return NSAttributedString(attachment: attachment)
    }
}
